// xc_lshop/distr/shareholder/com/timenav.js

Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    searchmodel: Object,
    type: {
      type: String,
      value: "day"
    }

  },

  /**
   * 组件的初始数据
   */
  data: {
    navstatus: 5,
    daynav: [{
        status: 1,
        name: "选择日期"
      },
      {
        status: 2,
        name: "本月"
      },
      {
        status: 3,
        name: "本季度"
      },
      {
        status: 4,
        name: "本年"
      },
      {
        status: 5,
        name: "至今"
      },
    ],
    monthnav: [{
        status: 9,
        name: "今年"
      },
      {
        status: 7,
        name: "去年"
      },
      {
        status: 6,
        name: "前年"
      },
      {
        status: 8,
        name: "选择年份"
      },
    ],
    years: []
  },
  ready() {
    var update = {}
    if (this.data.type == "day") {
      update["nav"] = this.data.daynav
    } else {
      update["navstatus"] = 9
      update["nav"] = this.data.monthnav
      // var year = date.getFullYear();
      // var years=[];
      // for(var i=2019;i++;i<=2022){
      //   years.push(i)
      // }
      // update["years"]=years
    }
    this.setData(update)
  },


  /**
   * 组件的方法列表
   */
  methods: {
    bindDateChange(e) {

      if (e.detail.value) {
        this.setData({
          year: e.detail.value,
          'searchmodel.year': e.detail.value
        })
        this.change()
      }
    },
    search(e) {
      var name = 'searchmodel.' + e.detail.val
      this.setData({
        [name]: e.detail.value
      })

      this.change()

    },
    onNavClick(e) {
      var status = e.currentTarget.dataset.status
      this.setData({
        navstatus: status,
        'searchmodel.navstatus': status
      })
      if (status != 1) {
        this.change()
      }
    },
    change() {
      var strwhere = this.data.searchmodel
      var myEventDetail = strwhere // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('navclick', myEventDetail, myEventOption)
    }
  }
})